namespace LDNS.SDK.Commands.Models
{
    /// <summary>
    /// 获取启动时间命令
    /// 用于获取DNS服务的启动时间戳
    /// 作者：huobing
    /// </summary>
    public sealed class GetStartTimeCommand : BaseCommand<GetStartTimeResult>
    {
        public const string NAME = "GET_START_TIME";
        public override string Name => NAME;
        public override string Format => "GET_START_TIME";
        public override string Description => "获取DNS服务的启动时间戳";
        public override CommandPermission Permission => CommandPermission.User;
        public override bool Validate(string[] args, out string error) 
        { 
            error = string.Empty; 
            return args.Length == 0 || (error = "此命令不接受参数") == string.Empty; 
        }
    }

    /// <summary>
    /// 获取启动时间命令执行结果
    /// 作者：huobing
    /// </summary>
    public class GetStartTimeResult : BaseCommandResult
    {
        /// <summary>
        /// 服务启动时间（本地时间）
        /// </summary>
        public DateTime StartTimeLocal { get; set; }
        
        /// <summary>
        /// 控制台输出格式化
        /// </summary>
        /// <returns>格式化后的启动时间信息</returns>
        public override string ToConsoleString()
        {  
            var sb = new System.Text.StringBuilder();
            
            if (!string.IsNullOrEmpty(Message))
            {
                sb.AppendLine(Message);
            }
            else
            {
                sb.AppendLine("服务启动时间信息：");
            }
            
            sb.AppendLine($"启动时间（本地）: {StartTimeLocal.ToString("yyyy-MM-dd HH:mm:ss")}");
            
            // 计算运行时长
            TimeSpan uptime = DateTime.Now - StartTimeLocal;
            sb.AppendLine($"运行时长: {uptime.Days}天 {uptime.Hours}小时 {uptime.Minutes}分钟 {uptime.Seconds}秒");
            
            return sb.ToString().TrimEnd();
        }
    }
}